package com.lk.basic.service.impl;

import com.lk.basic.mapper.BaseMapper;
import com.lk.basic.query.BaseQuery;
import com.lk.basic.service.IBaseService;
import com.lk.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void insert(T t) {
        baseMapper.insert(t);
    }

    @Override
    @Transactional
    public void delete(Serializable id) {
        baseMapper.delete(id);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public T selById(Serializable id) {
        return baseMapper.selById(id);
    }


    @Override
    public List<T> selAll() {
        return baseMapper.selAll();
    }

    @Override
    public PageList<T> queryPage(BaseQuery query) {
        Long total = baseMapper.queryTotal(query);
        if (total<0){
            return new PageList<>();
        }
        List<T> lists=baseMapper.queryDatas(query);
        return new PageList<>(total,lists);
    }
}
